package com.kaifamiao.comparing;

import java.util.Arrays;
import java.util.Comparator;

public class CompareString {
    public static void main(String[] args) {
        String[] names = { "和和", "美美", "团团", "圆圆", "平平", "安安" };
        System.out.println( Arrays.toString( names ) );

        // 自然排序
        Arrays.sort( names );

        System.out.println( Arrays.toString( names ) );

        System.out.println( "和和".compareTo("美美") );
        System.out.println( "美美".compareTo("和和") );

        System.out.println( "- ".repeat( 20 ) );

        // 用比较器对 names 数组进行整体排序(从"大"到"小")
        Arrays.sort(names, new Comparator<String>() {
            @Override
            public int compare(String s1, String s2) {
                return -s1.compareTo(s2);
            }
        });

        System.out.println( Arrays.toString( names ) );
    }
}
